
#import "UIBarButtonItem+Pyw.h"
#import "UIImage+Pyw.h"

@implementation UIBarButtonItem (Pyw)

/**
 * locationType YES表示左边item，NO表示右边item
 */
+ (instancetype)barButtonItemWithImageName:(NSString *)name
                             highImageName:(NSString *)highName
                              locationType:(BOOL)locationType
                                    target:(id)target
                                    action:(SEL)selector
{
    UIButton *btn = [[UIButton alloc] init];
    UIImage *image = [UIImage imageWithName:name];
    [btn setImage:image forState:UIControlStateNormal];
    [btn addTarget:target
            action:selector
  forControlEvents:UIControlEventTouchUpInside];
    
    if(locationType) {
        btn.frame = CGRectMake(0, 0, image.size.width, image.size.width);
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        
    } else {
        btn.frame = CGRectMake(0, 0, 81, 30);
        btn.userInteractionEnabled = NO;
    }
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return item;
}

+ (instancetype)barButtonItemWithImageName:(NSString *)name{
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setImage:[UIImage imageWithName:name] forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 0, 20, 40);

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return item;
}

@end
